#include "ClientContextExt.h"
#include "ITransHandler.h"

ClientContextExt::ClientContextExt()
	:m_srcHandler(NULL),m_destHandler(NULL),m_ovl2(NULL),m_buffer2(NULL),m_weakRefBuf2(NULL)
	
{
}

ClientContextExt::~ClientContextExt()
{
	if(m_srcHandler!=NULL)
	{
		delete m_srcHandler;
	}
	if(m_ovl2!=NULL)
	{
		delete m_ovl2;
	}
	if(m_buffer2!=NULL)
	{
		delete []m_buffer2->buf;
		delete m_buffer2;
	}
	if(m_weakRefBuf2!=NULL)
	{
		delete m_weakRefBuf2;
	}
	if(m_destHandler!=NULL)
	{
		delete m_destHandler;
	}
}

void ClientContextExt::Initalize()
{
	InitAsyncParam(&m_ovl2,&m_buffer2);
	m_weakRefBuf2=new WSABUF();
}

void ClientContextExt::InitAsyncParam(OVERLAPPED **ovl,WSABUF **buffer)
{
	*ovl=new OVERLAPPED();
	*buffer=new WSABUF();
	::ZeroMemory(*ovl,sizeof(OVERLAPPED));
	(*buffer)->buf=new char[CLIENTCONTEXT_BUFFER_SIZE];
	(*buffer)->len=CLIENTCONTEXT_BUFFER_SIZE;
}